package com.hehui.partimejob.fragment;

import android.annotation.SuppressLint;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.hehui.partimejob.LoginActivity;
import com.hehui.partimejob.R;
import com.hehui.partimejob.adapter.MyRecyclerViewAdapter;
import com.hehui.partimejob.items.adapterItem.MainFunctionNavItem;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

public class MyFragment extends BaseFragment {
    private LinearLayout topTab;
    private CircleImageView headPhoto;
    private TextView username;
    private RecyclerView itemRv;


    @Override
    public void init() {
        getNav().setTitle(getString(R.string.my)).isShowBack(false);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_my;
    }

    @Override
    protected void begin(Bundle bundle) {

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();

        String[]navItems = getResources().getStringArray(R.array.my_nav_item);

        @SuppressLint("Recycle") TypedArray navIconItems = getResources().obtainTypedArray(R.array.my_nav_icon);
        ArrayList<MainFunctionNavItem> list = new ArrayList<MainFunctionNavItem>();
        for (int i = 0; i < navItems.length; i++) {
            MainFunctionNavItem mainFunctionNavItem = new MainFunctionNavItem();
            mainFunctionNavItem.setIcon(navIconItems.getDrawable(i));
            mainFunctionNavItem.setTitle(navItems[i]);
            list.add(mainFunctionNavItem);
        }
        itemRv.setAdapter(new MyRecyclerViewAdapter<MainFunctionNavItem>(list, R.layout.rv_main_fun_nav_item) {
            @Override
            protected void handleData(InnerHolder holder, MainFunctionNavItem item) {
                holder.setBgDrawable(R.id.icon, item.getIcon())
                        .setText(R.id.title, item.getTitle());
            }

        });
        topTab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                A.startActivity(LoginActivity.class);
            }
        });


    }


    private void initView() {

        topTab = (LinearLayout) findViewById(R.id.topTab);
        headPhoto = (CircleImageView) findViewById(R.id.headPhoto);
        username = (TextView) findViewById(R.id.username);
        itemRv = (RecyclerView) findViewById(R.id.itemRv);
    }


}
